package com.shangxia.basic.common.mybatis.dynamicsource;

import java.util.ArrayList;
import java.util.List;

/**
 * @ProjectName: MyDemo_zy
 * @ClassName: DynamicDataSourceContextHolder
 * @Time: 2020-04-01 19:48
 * @Author: zhou24
 * @Description:
 * @Experience:
 */
public class DynamicDataSourceContextHolder {
    private static final ThreadLocal<String> CONTEXT_HOLDER = new ThreadLocal<>();
    public static List<String> dataSourceIds = new ArrayList<>();

    public static void setDataSourceType(String dataSourceType) {
        CONTEXT_HOLDER.set(dataSourceType);
    }

    public static String getDataSourceType() {
        return CONTEXT_HOLDER.get() == null ? ResourceTypeEnum.BASE : CONTEXT_HOLDER.get();
    }

    public static void clearDataSourceType() {
        CONTEXT_HOLDER.remove();
    }

    public static boolean containsDataSource(String dataSourceId) {
        return dataSourceIds.contains(dataSourceId);
    }
}
